### The GIM root directory
GIMDIR = ..
OPTS = 
CC=gcc
CXX=g++

CFLAGS=-Wall $(DEBUG) $(DEFINITIONS) $(CINCLUDES) $(CMISCFLAGS) $(LIBDIRS) $(OPTS) `xml2-config --cflags`
CPPFLAGS=-Wall  $(DEBUG) $(EXCEPTIONS) $(CPPINCLUDES) \
				$(DEFINITIONS) $(CPPMISCFLAGS) $(LIBDIRS) $(OPTS)
DEBUG=-O3 -g3
CMISCFLAGS=
CPPMISCFLAGS=
DEFINITIONS=-DLINUX_OS -D_GNU_SOURCE -DOS_LINUX -DT_GROUND_MODEL_MAP_DEBUG
EXCEPTIONS=-fexceptions

CINCLUDES=$(OCCU_INCLUDE) -I. $(INCGIMI)
CPPINCLUDES=$(OCCU_INCLUDE) -I$(GIMDIR)/glutImageGUI -I$(GIMDIR)/utils \
						-I$(GIMDIR)/ImageUtils/JPEGEncoder $(LNMINC) $(INCGIMI) -I/usr/local/include/opencv
LIBDIRS=

LD=g++
LDFLAGS=$(LIBDIRS)

LIBS=-lrt -lpthread -lGL -lGLU -lglut -ljpeg $(LIBSGIMI) -lcv

CSRCUTIL = $(GIMDIR)/utils/ownutils.c $(GIMDIR)/utils/owndebug.c
CPPIMAGEGUI = $(GIMDIR)/glutImageGUI/glutImageGUI.cpp
CPPJPEG = $(GIMDIR)/ImageUtils/JPEGEncoder/JPEGEncoder.cpp

SRCSC=$(OCCU_SRC_C) $(CSRCUTIL)
SRCSCPP=occutest.cpp $(OCCU_SRC_CPP) $(CPPIMAGEGUI) $(CPPJPEG)
VPATH=
SRC_HM=$(LNMSRC) TBasicGrid.cpp TGroundModelMap.cpp TMetricGrid.cpp

SRC_GRID_SERVER_C=$(CGIMI) $(OCCU_SRC_C)
SRC_GRID_SERVER_CPP=$(OCCU_SRC_CPP) $(CPPIMAGEGUI) $(CPPGIMI) CGridGServerModule.cpp \
  GridServer.cpp ../stereoCR/GImage.cpp ../stereoCR/DenseStereoImage.cpp \
  ../stereoCR/StereoRoutines.cpp \
  ../stereoCR/alg_disparity/DenseStereoDisparity_Simple_1.cpp \
  ../stereoCR/alg_structure/DenseStereoStructure_My1.cpp \
  ../imageclient/imageclientinterface/CImageClient.cpp

SRC_GRID_CLIENT_C=$(CGIMI) $(OCCU_SRC_C)
SRC_GRID_CLIENT_CPP=GridClient.cpp $(OCCU_SRC_CPP) $(CPPGIMI) CGLHeightMap.cpp glutHeightMapDisplay.cpp

include $(GIMDIR)/grid/Makefile.occu
include $(GIMDIR)/LnMlib/src/Makefile.lnmdata
GDIR=$(GIMDIR)
include $(GIMDIR)/GIMI/Makefile.gimi

## Construct final lists of CPP and C objects
OBJSC=$(SRCSC:.c=.o)
OBJSCPP=$(SRCSCPP:.cpp=.opp)

OBJ_LNM=$(SRC_HM:.cpp=.opp)

OBJ_GSERVER_C=$(SRC_GRID_SERVER_C:.c=.o)
OBJ_GSERVER_CPP=$(SRC_GRID_SERVER_CPP:.cpp=.opp)

OBJ_GCLIENT_C=$(SRC_GRID_CLIENT_C:.c=.o)
OBJ_GCLIENT_CPP=$(SRC_GRID_CLIENT_CPP:.cpp=.opp)

## Define compiles and links
COMPILEC=$(CC) $(CFLAGS) $(CINCLUDES) -c
COMPILECPP=$(CXX) $(CPPFLAGS) $(CPPINCLUDES) -c
LINK=$(LD) $(LDFLAGS) $(LIBS)

.PHONY: all clean realclean

all: grid hm gserver gclient
##witbin: $(OBJSC) $(OBJSCPP)

grid: $(OBJSC) $(OBJSCPP)
			$(LINK) -o $@ $(OBJSC) $(OBJSCPP)

hm: $(OBJ_LNM)
			$(LINK) -o $@ $(OBJ_LNM)

gserver: $(OBJ_GSERVER_C) $(OBJ_GSERVER_CPP)
				$(LINK) -o $@ $(OBJ_GSERVER_C) $(OBJ_GSERVER_CPP)

gclient: $(OBJ_GCLIENT_C) $(OBJ_GCLIENT_CPP)
				$(LINK) -o $@ $(OBJ_GCLIENT_C) $(OBJ_GCLIENT_CPP)

clean: 
	rm -f *.opp *.o grid hm gserver gclient *.out *~ *.d *.dpp

realclean:
	rm -f $(OBJSC) $(OBJSCPP) $(OBJ_LNM) $(OBJ_GSERVER_C) $(OBJ_GSERVER_CPP) $(OBJ_GCLIEN_C) $(OBJ_GCLIEN_CPP)\
 		grid hm gserver *.out *~ *.d *.dpp *.opp *.o

##manual:
##	doxygen

## Compile rule for all .o (.c) file
%.o:    %.c
				$(COMPILEC) -o $@ $<

## Compile rule for all .opp (.cpp) files
%.opp:	%.cpp
				$(COMPILECPP) -o $@ $<

## Dependency generation rule: For all required '.d' files
%.d:	  %.c
				$(CC) -MM $(CFLAGS) $< > $@.$$$$; \
				sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
				rm -f $@.$$$$

## Dependency generation rule: For all required '.dpp' files
%.dpp:	%.cpp
				$(CXX) -MM $(CPPFLAGS) $< > $@.$$$$; \
				sed 's,\($*\)\.o[ :]*,\1.opp $@ : ,g' < $@.$$$$ > $@; \
				rm -f $@.$$$$

%.h:	%.h

# Include dependency rules
-include $(SRCSCPP:.cpp=.dpp)
-include $(SRCSC:.c=.d)
